package board;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.File;
import java.io.Reader;
import java.io.IOException;

import board.model.*;

public class deleteReplyAction extends ActionSupport {
	
	public static Reader reader;
	public static SqlMapClient sqlMapper;
	
	private ReplyVO paramClass;
	private ReplyVO resultClass;       
	
	private String fileUploadPath = "C:\\java\\upload\\";
	
	private int Rep_no;
	
	public deleteReplyAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
	}
	public String execute() throws Exception {
		
		paramClass = new ReplyVO();
		resultClass = new ReplyVO();
		
		resultClass = (ReplyVO) sqlMapper.queryForObject("selectOne", getRep_no());
		
		File deleteFile = new File(fileUploadPath + resultClass.getFile_savname());
		deleteFile.delete();
		
		paramClass.setRep_no(getRep_no());
		
		sqlMapper.update("deleteReply", paramClass);
		
		return SUCCESS;
	}
	
	public ReplyVO getParamClass() {
		return paramClass;
	}
	public void setParamClass(ReplyVO paramClass) {
		this.paramClass = paramClass;
	}

	public ReplyVO getResultClass() {
		return resultClass;
	}
	public void setResultClass(ReplyVO resultClass) {
		this.resultClass = resultClass;
	}
	public int getRep_no() {
		return Rep_no;
	}
	public void setRep_no(int rep_no) {
		Rep_no = rep_no;
	}
}
